﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Xml.Serialization;
using System.IO;

namespace Defilade
{
    [Serializable]
    public class Settings
    {
        public const String SETTINGS_FILE = "settings.xml";

        public Settings()
        {
            LastPlayerCoordinate = new MapLocation("0.0.0", "0.0.0");
            LastTargetCoordinate = new MapLocation("0.0.0", "0.0.0");
            UseVoiceRecognition = false;
            UseTextToSpeech = false;
            ConfirmVoiceCoordinates = false;
        }

        public Settings(Settings toCopy)
        {
            LastPlayerCoordinate = toCopy.LastPlayerCoordinate;
            LastTargetCoordinate = toCopy.LastTargetCoordinate;
            UseVoiceRecognition = toCopy.UseVoiceRecognition;
            UseTextToSpeech = toCopy.UseTextToSpeech;
            ConfirmVoiceCoordinates = toCopy.ConfirmVoiceCoordinates;
        }

        public MapLocation LastPlayerCoordinate
        {
            get;
            set;
        }

        public MapLocation LastTargetCoordinate
        {
            get;
            set;
        }

        public bool UseVoiceRecognition
        {
            get;
            set;
        }

        public bool UseTextToSpeech
        {
            get;
            set;
        }

        public bool ConfirmVoiceCoordinates
        {
            get;
            set;
        }

        public static Settings LoadFrom(String file)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Settings));
            Settings loadedSettings = null;
            using(Stream reader = new FileStream(file, FileMode.Open)){
                loadedSettings = (Settings) serializer.Deserialize(reader);
            }
            return loadedSettings;
        }

        public void SaveTo(String file)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Settings));
            using (Stream writer = new FileStream(file, FileMode.Create))
            {
                serializer.Serialize(writer, this);
            }
        }
    }
}
